layui.config({
	base : "/crmCustomer/js/"
}).use(['form','layer','jquery'],function(){
	var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : parent.layer,

		$ = layui.jquery;
	//video背景
	$(window).resize(function(){
		if($(".video-player").width() > $(window).width()){
			$(".video-player").css({"height":$(window).height(),"width":"auto","left":-($(".video-player").width()-$(window).width())/2});
		}else{
			$(".video-player").css({"width":$(window).width(),"height":"auto","left":-($(".video-player").width()-$(window).width())/2});
		}
	}).resize();
	
	// //登录按钮事件
	// form.on("submit(login)",function(data){
	// 	console.log("data is :"+data)
     //    // if(data=="success"){
	// 		// window.location.href = "../page/main.html";
     //    // }
     //    // return true;
	// })
})


$(document).keydown(function(event) {
    if (event.keyCode == 13) {
        $("#loginButton").click();
    }
});

//刷新验证码
function refresh() {
    $('#chche').attr("src", "/crmCustomer/getCaptcha");
}

function login(){

    var username = $("#username").val();
    var password = $("#password").val();
    var validateCode = $("#validateCode").val();

    if(username==""){
        //layui-layer layui-layer-dialog layui-layer-border layui-layer-msg
        $("#username").val("");
        $("#username").focus();
        layer.msg("用户名不能为空");

        return;
    }

    if(password==""){
        $("#password").val("");
        $("#password").focus();
        layer.msg("密码不能为空");
        return;
    }

    if(validateCode==""){

        $("#validateCode").val("");
        $("#validateCode").focus();
        layer.msg("验证码不能为空");
        return;
    }

    $.ajax({
        type : "post",
        async: false,
        data:"username=" + username + "&password=" + password + "&validateCode=" + validateCode , //$('#form1').serialize(),//
        url : "/crmCustomer/login",
        dataType : "json",
        success : function(data){
            if(data!=''&&data!=null){
                if(data.success){
                    window.location.href = "/crmCustomer/page/main";
                }else{
                    if(data.message=='验证码错误'){
                        $('#chche').attr("src", "/crmCustomer/getCaptcha");
                        $("#validateCode").val("");
                    }
                    layer.msg(data.message);

                }
            }
            console.log(data)
        },
        error:function(data){
            console.log(data);
            layer.msg("登录失败");
        }
    });
}

